#include <iostream>
#include <string>
#include <cctype>

int prime(int a) {
  int p = 1;
  if (a < 2) {
    p = 0;
  } else {
    for (int i = 2; i <= a/2; i++) {
      if (a % i == 0) {
        p = 0;
        break;
      }
    }
  }
  return p;
}

int main() {
  std::string input;
  std::getline(std::cin, input);

  std::string words[] = {" ","one", "two", "three", "four", "five", "six", "seven", "eigth", "nine", "zero"};
  std::string numbers[] = {"","1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};
  for (int i = 0; i < 10; i++) {
    size_t pos = input.find(words[i]);
    while (pos != std::string::npos) {
      input.replace(pos, words[i].length(), numbers[i]);
      pos = input.find(words[i], pos + 1);
    }
  }
  if (input.length() == 3 && std::isdigit(input[0]) && std::isdigit(input[1]) && std::isdigit(input[2])) {
    int a = std::stoi(input);
    int b = a;
    int c = a;
    if (prime(a) == 1) {
      std::cout << a << std::endl;
    } else {
      while (true) {
        b--;
        c++;
        if (prime(b) == 1) {
          std::cout << b << std::endl;
          break;
        }
        if (prime(c) == 1) {
          std::cout << c << std::endl;
          break;
        }
      }
    }
  } else {
    std::cout << "Wrong input" << std::endl;
  }

  return 0;
}

